package com.example.client;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.image.Image;
import javafx.stage.Stage;

import java.io.IOException;

public class ChooseViewController {
    @FXML
    private ComboBox ChooseBox;
    @FXML
    private Button closeBtn;

    @FXML
    public String choose() {
        String portstr= (String) ChooseBox.getValue();
        return portstr;
    }

    public String getPort(ChooseViewController p) {
        if (p.choose().equals("长沙市天心区"))
            return "长沙市天心区";
        if (p.choose().equals("长沙市芙蓉区"))
            return "长沙市芙蓉区";
        if (p.choose().equals("长沙市开福区"))
            return "长沙市开福区";
        else
            return "长沙市雨花区";
    }
    public void enter(ActionEvent actionEvent) {

        try {
            Stage stage = new Stage();
            FXMLLoader fxmlLoader = new FXMLLoader(Client.class.getResource("Client.fxml"));
            Scene scene = new Scene(fxmlLoader.load(), 395, 520);
            //将地点信息与端口号对应并传到下一个界面
            ClientController target = fxmlLoader.getController();
            target.addressText.setText(getPort(this));
            stage.setTitle("温度采集模拟器客户端");
            stage.getIcons().add(new Image(Client.class.getResource("logo.png").toExternalForm()));
            stage.setScene(scene);
            stage.show();
            //关闭当前窗口
//            Stage primaryStage = (Stage) closeBtn.getScene().getWindow();
//            primaryStage.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void close(ActionEvent actionEvent) {
        // get a handle to the stage
        Stage stage = (Stage) closeBtn.getScene().getWindow();
        // do what you have to do
        stage.close();
    }

}
